var mongoose = require('mongoose');

var logger = require('./logger');
var CONSTS = require('../consts');

mongoose.Promise = global.Promise;

var opts = {
	user: CONSTS.DATABASE.USER,
	pass: CONSTS.DATABASE.PASS,
	server: {
		auto_reconnect: CONSTS.DATABASE.AUTORECONNECT,
		poolSize: CONSTS.DATABASE.POOLSIZE
	}
};
mongoose.connect(CONSTS.DATABASE.HOST, CONSTS.DATABASE.NAME, CONSTS.DATABASE.PORT, opts);

mongoose.connection.on('error', function(err) {
    logger.debug('Mongoose connection error: ' + err);
});

module.exports = mongoose;